<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags"%>

<t:masterpage>
	<jsp:body>
        <c:url value="/staff" var="staffUrl" />
        <h2>${personEditorPageModel.title}</h2>
        <joda:format var="formattedDate"
			value="${personEditorPageModel.person.birthday}" pattern="dd.MM.yyyy" />
        <form:form method="post"
			action="${staffUrl}/${personEditorPageModel.formAction}.html"
			modelAttribute="personEditorPageModel" enctype="multipart/form-data">
			<div class="horizontal_pad">
            <form:hidden path="person.id" />
            <form:hidden path="person.authToken" />
            <form:hidden path="person.photoPath" />
            <table>
                <tr>
                    <th><form:label path="person.firstName">First name</form:label></th>
                    <td class="horizontal_pad"><form:input
								path="person.firstName" /></td>
                    <td><form:errors path="person.firstName" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.middleName">Middle name</form:label></th>
                    <td class="horizontal_pad"><form:input
								path="person.middleName" /></td>
                    <td><form:errors path="person.middleName" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.lastName">Last name</form:label></th>
                    <td class="horizontal_pad"><form:input
								path="person.lastName" /></td>
                    <td><form:errors path="person.lastName" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.birthday">Birthday</form:label></th>
                    <td class="horizontal_pad"><form:input
								path="person.birthday" value="${formattedDate}" /></td>
                    <td><form:errors path="person.birthday" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.email">Email</form:label></th>
                    <td class="horizontal_pad"><form:input
								path="person.email" type="email" /></td>
                    <td><form:errors path="person.email" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.photoPath">Photo</form:label></th>
                    <td class="horizontal_pad"><form:input path="fileData" type="file" title="Browse..."/></td>
                	<td><form:errors path="person.photoPath" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.position.id">Position</form:label></th>
                    <td class="horizontal_pad"><form:select
								path="person.position.id">
                    <c:forEach var="position"
									items="${personEditorPageModel.positions}">
                            <form:option value="${position.id}">
                                <c:out value="${position.name}" />
                            </form:option>
                        </c:forEach>
                    </form:select></td>
                    <td><form:errors path="person.position.id" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.department.id">Department</form:label></th>
                    <td class="horizontal_pad"><form:select
								path="person.department.id">
                    <c:forEach var="department"
									items="${personEditorPageModel.departments}">
                            <form:option value="${department.id}">
                                <c:out value="${department.name}" />
                            </form:option>
                        </c:forEach>
                    </form:select></td>
                    <td><form:errors path="person.department.id" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.wantToReceive">Subscribed</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								path="person.wantToReceive" /></td>
                    <td><form:errors path="person.wantToReceive" /></td>
                </tr>
                <tr>
                    <th><form:label path="person.wantToCelebrate">Want to celebrate</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								path="person.wantToCelebrate" /></td>
                    <td><form:errors path="person.wantToCelebrate" /></td>
                </tr>                
                <tr>
                    <th><form:label path="saveAsUser">User</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								id="saveAsUser" path="saveAsUser" /></td>
                    <td><form:errors path="saveAsUser" /></td>
                </tr>
                <c:if test="${personEditorPageModel.showPasswordInput}"> 
                    <tr class="userRelated">
                        <th><form:label path="password">Password</form:label></th>
                        <td class="horizontal_pad"><form:password
									path="password" /></td>
                        <td><form:errors path="password" /></td>
                    </tr>
                </c:if>
                <tr class="userRelated">
                    <th><form:label path="role.add">Can create</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								path="role.add" /></td>
                    <td><form:errors path="role.add" /></td>
                </tr>
                <tr class="userRelated">
                    <th><form:label path="role.update">Can update</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								path="role.update" /></td>
                    <td><form:errors path="role.update" /></td>
                </tr>
                <tr class="userRelated">
                    <th><form:label path="role.delete">Can delete</form:label></th>
                    <td class="horizontal_pad"><form:checkbox
								path="role.delete" /></td>
                    <td><form:errors path="role.delete" /></td>
                </tr>
            </table>
            </div>
            <div class="form-actions">
            	<input class="btn btn-primary" type="submit"
					value="${personEditorPageModel.submitText}" />
            </div>
        </form:form>       
    </jsp:body>
</t:masterpage>